//localStorage.setItem('user', '{"id":1,"username":"admin","password":null,"createTime":"2018-06-12T15:14:16.000+0000","updateTime":"2018-07-06T10:13:54.000+0000","state":0,"nickname":"超级管理员","mobile":"18188888888","email":"admin@6cc0.com","ip":"192.168.0.1","authorities":[{"authority":"test"},{"authority":"admin"}],"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true}');
//localStorage.setItem('token', '{"access_token":"02bad6cc-d69f-4cd3-a3ff-4ac91b269483","token_type":"bearer","refresh_token":"377bb095-64f2-476e-ac74-2ab3232cfc62","expires_in":43199,"scope":"all","exp":2531683080720}');

//if(!hasAuthority('admin')) {
//	location.href = '/';
//}

function houTai(template) {
	return {
		template: template,
		data: function() {
			return {
				isCollapse: false,
				menu: {}
			};
		},
		computed: {
			collapseIcon: function() {
				return this.isCollapse ? 'el-icon-caret-right' : 'el-icon-caret-left';
			}
		},
		methods: {
			htCollapse: function() {
				this.isCollapse = !this.isCollapse;
			},
			handleSelect: function(key, keyPath) {
				if(/^(https?|ftp|file):\/\//g.test(key)) {
					open(key);
				} else if(/.(html|rar)$/g.test(key)) {
					location.href = CONST_STATIC_URL + '/hou-tai/' + key;
				}
				this.menu.defaultActive = key;
			},
			shouYe: function() {
				location.href = CONST_STATIC_URL + '/';
			}
		},
		created: function() {
			this.user = JSON.parse(localStorage.getItem('user'));
		},
		mounted: function() {
			this.$nextTick(function() {
				var _this = this;
				axios('json/menu.json').then(function(response) {
					_this.menu = response.data;
					var url = location.pathname.split('/');
					_this.menu.defaultActive = url[url.length - 1];
				});
				checkToken().then(function() {
					var token = localStorage.getItem('token');
					if(token != null) {
						token = JSON.parse(token);
						authAxios.defaults.headers.common['Authorization'] = token.token_type + ' ' + token.access_token;
					}
				});
			});
		}
	};
}

Vue.component('hou-tai', function(resolve, reject) {
	axios('hou-tai.html').then(function(response) {
		resolve(houTai(response.data));
	});
});